<template>
  <div class="achievement">
    <div class="achievement-header clearfix">
      <ul class="item fl">
        <li
          v-for="(item, index) in items"
          :key="index"
          @click="selectItem(item.type,index,item.year)"
        >
          <span :class="[current == index ? 'cur' : '']">{{item.name}}</span>
        </li>
      </ul>
      <ul class="date fr" @click="showData">
        <li class="date_time" :class="info=='按条件查询'?'':'active'">
          <span>{{info}}</span>
          <svg-icon icon-class="icon_right" class="date-hide"></svg-icon>
        </li>
      </ul>
    </div>
    <div class="whole">
      <div class="total">
        <div class="content">
          <img class="price-bg" src="https://img.wifenxiao.com/h5-wfx/images/DZ/jlsj/total-prices.png" />
          <div class="jackpot">
            <div class="now-title">奖池总额</div>
            <div class="money"><span>￥</span>{{jackpot_total_amount}}</div>
          </div>
        </div>
        <div class="content top">
          <img class="price-bg" src="https://img.wifenxiao.com/h5-wfx/images/DZ/jlsj/expected-obtains.png" />
          <div class="jackpot">
            <div class="expected-title">我获得了</div>
            <div class="expected-money"><span>￥</span>{{bonus}}</div>
          </div>
        </div>
      </div>
    </div>
    <date-pop
      @cancel="cancelTime"
      @confirm="selectTime"
      :current="type"
      v-if="show_date"
      :timeData="timeData"
    ></date-pop>
  </div>
</template>

<script>
import Vue from 'vue'
import 'vant/lib/index.css'
import { Popup } from 'vant'
import datePop from '@/views/user/components/datePop'
import { gzjlAgentBonus } from '@/api/dz/yjsjApi'
Vue.use(Popup)
export default {
  data() {
    return {
      current: 3,
      show_date: false,
      currentYear: '',
      currentMonth: '',
      currentQuarter: '',
      type: '',
      isShow: true,
      items: [],
      timeData: {},
      info: '按条件查询',
      jackpot_total_amount: '',
      count: '',
      bonus: ''
    }
  },
  created() {
    this.init()
  },
  methods: {
    init() {
      this.getTime()
      this.getDhsGlj()
    },
    selectItem(type, index, year) {
      this.current = index
      this.currentYear = year
      this.currentMonth = type
      this.timeData.currentMonth = type
      if (this.month == type) {
        this.isShow = true
      } else {
        this.isShow = false
      }
      this.getDhsGlj()
      this.info = '按条件查询'
    },
    selectTime(e) {
      this.currentYear = e.selectYear
      this.currentMonth = e.selectMonth
      this.currentQuarter = e.selectQuarter
      this.timeData.currentYear = e.selectYear
      this.timeData.currentMonth = e.selectMonth
      this.timeData.currentQuarter = e.selectQuarter
      // this.current = -1;
      this.getDhsGlj()
      if (this.type == 1) {
        this.info = this.currentYear + '年' + this.currentMonth + '月'
        if (this.month == this.currentMonth) {
          this.isShow = true
        } else {
          this.isShow = false
        }
      } else if (this.type == 2) {
        this.info =
          this.currentYear + '年' + '第' + this.currentQuarter + '季度'
        if (this.quarter == this.currentQuarter) {
          this.isShow = true
        } else {
          this.isShow = false
        }
      } else {
        this.info = this.currentYear + '年'
        if (this.year == this.currentYear) {
          this.isShow = true
        } else {
          this.isShow = false
        }
      }
      // console.log(this.isShow)
      this.show_date = false
    },
    cancelTime() {
      // console.log('取消')
      this.show_date = false
    },
    showData() {
      this.show_date = true
    },
    // 路由跳转
    Jump(url, data) {
      this.$JumpPath(this, url, data)
    },

    // 数据请求
    getDhsGlj() {
      const data = {
        value: this.timeData.currentMonth,
        year: this.timeData.currentYear
      }
      this.$loadingWrap.show()
      setTimeout(() => {
        this.$loadingWrap.close()
      }, 50000)
      gzjlAgentBonus(data).then(res => {
        this.$loadingWrap.close()
        if (res.status == 1) {
          this.jackpot_total_amount = res.data.jackpot_total_amount
          this.count = res.data.count
          this.bonus = res.data.bonus
          this.timeData.year = res.data.year_list
          this.timeData.month = res.data.month_list
          this.timeData.currentYear = res.data.year
          this.timeData.currentMonth = res.data.month
          this.timeData.quarter = res.data.quarter
          this.commission = res.data.detail.all_amount
          this.type = res.data.dhs_team_bonus_time_type
          this.lower_level_user_num = res.data.detail.lower_level_user_num
          this.reward = res.data.detail.reward
          this.group_link = res.data.group_link
          this.personal_consume = res.data.personal_consume
        } else {
          this.$Error(res.msg)
        }
      })
    },

    // 获取当前月份和前三个月份
    getTime() {
      const time = new Date()
      const currentMonth = time.getMonth() + 1
      const currentYear = time.getFullYear()
      const currentQuarter = Math.ceil(currentMonth / 3)
      const item = [{ name: '本月', type: currentMonth, year: currentYear }]
      for (let i = 1; i <= 3; i++) {
        const month =
          currentMonth - i > 0 ? currentMonth - i : currentMonth - i + 12
        const year = currentMonth - i > 0 ? currentYear : currentYear - 1

        item.unshift({ name: month + '月', type: month, year: year })
      }
      // 当前年月
      this.currentYear = currentYear
      this.currentMonth = currentMonth
      this.currentQuarter = currentQuarter
      this.year = currentYear
      this.month = currentMonth
      this.quarter = currentQuarter
      this.items = item
      // console.log('item', item)
      this.timeData.currentYear = currentYear
      this.timeData.currentMonth = currentMonth
      this.timeData.currentQuarter = currentQuarter
    }
  },
  components: {
    datePop
  }
}
</script>

<style lang="scss">
@import "src/styles/variables";
@import "src/styles/mixin";
@import "src/styles/user/yejiStyle/index";
.achievement {
  .achievement-header {
    .fontSty {
      color: #f30c23;
      margin-left: 48px;
      font-size: 28px;
      line-height: 60px;
    }
  }
  .date-pop {
    z-index: 10!important;
  }
}
.whole {
  position: absolute;
  top: 100px;
  left: 0;
  width:100%;
  height: 1234px;
  background: url("https://img.wifenxiao.com/h5-wfx/images/DZ/jlsj/redBg.png") top left no-repeat;
  background-size: 100% 100%;
}
  .total {
    z-index: 10;
    position: relative;
    margin: 48px 54px 0 48px;
    .content {
      position: relative;
      &.top {
        margin-top: 24px;
      }
      .jackpot {
        position: absolute;
        left: 54px;
        top: 0;
        right: 54px;
        bottom: 0;
        text-align: center;
        font-weight: 600;
        .now-title{
          font-size: 36px;
          color: #F93B5A;
          line-height: 72px;
          margin-top: 12px;
        }
        .money {
          color: #F94661;
          font-size: 80px;
          margin-top: 120px;
          // margin: 60px 0 38px 0;
          span {
            font-size: 48px;
          }
        }
        .person-title {
          margin-bottom: 20px;
          img {
            width: 384px;
          }
        }
        .now-person {
          color: #F94661;
          font-size: 72px;
          span {
            font-size: 28px;
            color: #333;
            margin-left: 4px;
          }
        }
        .expected-title {
          color: #FEE9D9;
          font-size: 32px;
          font-weight: 600;
          margin-top: 16px;
        }
        .expected-money {
          margin-top: 144px;
          color: #A35E27;
          font-size: 80px;
          span {
            font-size: 48px;
          }
        }
      }
      .price-bg {
        width: 100%;
      }
    }
    
  }
</style>
